package com.dmai.capacity.platform.db;

import javax.sql.DataSource;

import com.dmai.capacity.platform.db.condition.DruidDataSourceCondition;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure;
import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder;
import com.alibaba.druid.spring.boot.autoconfigure.properties.DruidStatProperties;
import com.alibaba.druid.spring.boot.autoconfigure.stat.DruidFilterConfiguration;
import com.alibaba.druid.spring.boot.autoconfigure.stat.DruidSpringAopConfiguration;
import com.alibaba.druid.spring.boot.autoconfigure.stat.DruidStatViewServletConfiguration;
import com.alibaba.druid.spring.boot.autoconfigure.stat.DruidWebStatFilterConfiguration;
import com.baomidou.mybatisplus.autoconfigure.MybatisPlusAutoConfiguration;


@Configuration
@EnableConfigurationProperties({ DruidStatProperties.class })
@Import({ DruidSpringAopConfiguration.class, DruidStatViewServletConfiguration.class,
		DruidWebStatFilterConfiguration.class, DruidFilterConfiguration.class })
@AutoConfigureBefore(value = { DruidDataSourceAutoConfigure.class, MybatisPlusAutoConfiguration.class })
@Conditional(DruidDataSourceCondition.class)
public class DataSourceAutoConfig {

//	创建数据源
	@Bean
	@ConfigurationProperties("spring.datasource.druid")
	public DataSource dataSourceCore() {
		return DruidDataSourceBuilder.create().build();
	}

}
